package com.lq.util;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
 * Swagger配置类
 * 在与spring boot集成时，放在与Application.java同级的目录下。
 * 通过@Configuration注解，让Spring来加载该类配置
 * 在通过@EnableSwagger注解来启用Swagger
 * @author huaxin
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2 {
	
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				  .apiInfo(apiInfo())
				  .select()
				  .apis(RequestHandlerSelectors.basePackage("com.lq.controller"))
				  .paths(PathSelectors.any())
				  .build();
	}
	
	/**
	 * 创建API的基本信息（这些基本信息会展现在文档页面中）
	 * 访问地址 http://项目实际地址/swagger-ui.html
	 * @return
	 */
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("Spring Boot中使用Swagger构建RESTfuk API")
				.description("更多关注www.baidu.com")
				.contact("sunf")
				.version("1.0")
				.build();
	}
	
	
	
}
